/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bugsandcritters;

import java.util.ArrayList;
import java.awt.Graphics;
import java.awt.MouseInfo;

/**
 *
 * @author Robert Gibbons
 */
public class HudManager 
{
    public static ArrayList<HudBasic> Children = new ArrayList<HudBasic>();
    public static double MouseX;
    public static double MouseY;
    public static Boolean MousePressed = false;
    public static Boolean MousePressedPrevious = false;
    public static int Margin = 6;
    
    public HudManager()
    {
        AddChild(new ResetButton());
        AddChild(new RocksSlider());
        AddChild(new FlowersSlider());
        AddChild(new BugsSlider());
        AddChild(new CrittersSlider());
        AddChild(new PlayButton());
        AddChild(new PauseButton());
    }
    
    public void AddChild(HudBasic NewHud)
    {
        Children.add(NewHud);
        NewHud.Create();
    }   
    
    public void Update()
    {
        MousePressedPrevious = MousePressed;
        MousePressed = GameWindow.MousePressed;
        
        
        MouseX = MouseInfo.getPointerInfo().getLocation().x - 
                GameWindow.self.getX() -8;
        MouseY = MouseInfo.getPointerInfo().getLocation().y - 
                GameWindow.self.getY() -8;
        
        for(int i=0; i<Children.size();i++)
        {
            HudBasic h = Children.get(i);
            h.Update();
            
            if(MouseX + Margin > h.X && MouseX < h.X + h.Width + Margin &&
                    MouseY + Margin > h.Y + h.Height/2 && 
                    MouseY < h.Y + h.Height*1.5 + Margin &&
                    MousePressed && !MousePressedPrevious)
                h.OnClick();
        }
    }
    
    public void Draw(Graphics g)
    {
        for(int i=0; i<Children.size();i++)
        {
            HudBasic h = Children.get(i);
            h.Draw(g);
        }
    }
    
}
